package nontermin;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class NonTerminator implements Sign {
    private final String type;
    private final ArrayList<Sign> derivation = new ArrayList<>();
    public NonTerminator(String type) {
        this.type = type;
    }

    public void insertSig(Sign signal) {
        derivation.add(signal);
    }

    @Override
    public boolean isEmpty() {
        return derivation.isEmpty();
    }

    @Override
    public void output(FileWriter writer) {
        int len = derivation.size();
        for (int i = 0;i < len;i++) {
            derivation.get(i).output(writer);
        }
        boolean fl = type.equals("BlockItem") || type.equals("Decl")||
        type.equals("BType");
        if (fl) {
            return;
        }
        //System.out.println("<" + type + ">");
        try  {
            // 向文件中写入内容
            writer.write("<" + type + ">" + '\n');
        } catch (IOException e) {
            // 捕获并处理可能发生的IO异常
            System.out.println("An error occurred while writing to the file.");
            e.printStackTrace();
        }
    }
}
